package com.mxprojects.constructors
{
	import com.mxprojects.gui.Styles;
	
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	
	public class SimpleTextField extends TextField
	{
		public static const ENABLE_DRAGGING:String = "enableDragging";
				
		public var rows:int = 1;
		
		public function SimpleTextField(textString:String, rows:int = 1, isSelectable:Boolean = false, forceWidth:int = 0, usingCustomCSS:Boolean = false) {
			//basically just makes a very simple text box. nothing fancy.
			
			//set the default autosize
			autoSize = TextFieldAutoSize.LEFT;
			
			//if they want a set width
			if(forceWidth > 0){
				autoSize = TextFieldAutoSize.NONE;
				width = forceWidth;
				if(rows > 1){
					this.rows = rows;
					convertToMulti(rows);
				}
			}
			
			//set the stylesheet to be the CSS file
			if(usingCustomCSS){
				styleSheet = Styles.extraCss;
			}else{
				styleSheet = Styles.css;
			}
			
			//populate the text
			htmlText = textString;
		
			//if they don't want it to be selectable then disable the ability to be friendly to popups
			if(!isSelectable){
				selectable = false;
				name = ENABLE_DRAGGING;
			}
		}
		
		private function convertToMulti(rowCount:uint):void {
			//take a quick snapshot of the width
			var snapWidth:int = width;
			
			//set it to multiline and then do a loop to set the right height
			multiline = true;
			wordWrap = true;
			autoSize = TextFieldAutoSize.LEFT;
			
			//loop through the rows to add in the right amount
			var rowLoop:uint = 0;
			while(rowLoop < rowCount){
				appendText("\n");
				rowLoop++;
			}
			
			//take a snapshot of the current height
			var snapHeight:int = height;
			
			//turn off auto-size and then empty the input
			autoSize = TextFieldAutoSize.NONE;
			text = "";
			height = snapHeight;
			width = snapWidth;			
		}

	}
}